using RAG.Application.Dtos;

namespace RAG.Application.Interfaces;

/// <summary>
/// 向量服务接口
/// </summary>
public interface IVectorService
{
    /// <summary>
    /// 生成文本向量
    /// </summary>
    Task<float[]> GenerateEmbeddingAsync(string text);
    
    /// <summary>
    /// 批量生成向量
    /// </summary>
    Task<List<float[]>> GenerateEmbeddingsAsync(List<string> texts);
    
    /// <summary>
    /// 计算向量相似度
    /// </summary>
    Task<double> CalculateSimilarityAsync(float[] vector1, float[] vector2);
    
    /// <summary>
    /// 向量相似度搜索
    /// </summary>
    Task<List<VectorSearchResult>> SearchSimilarVectorsAsync(float[] queryVector, List<VectorData> vectors, int topK = 5);
    
    /// <summary>
    /// 保存向量到数据库
    /// </summary>
    Task<bool> SaveVectorAsync(Guid chunkId, float[] embedding);
    
    /// <summary>
    /// 从数据库获取向量
    /// </summary>
    Task<float[]?> GetVectorAsync(Guid chunkId);
    
    /// <summary>
    /// 删除向量
    /// </summary>
    Task<bool> DeleteVectorAsync(Guid chunkId);
}

/// <summary>
/// 向量搜索结果
/// </summary>
public class VectorSearchResult
{
    public Guid ChunkId { get; set; }
    public float[] Vector { get; set; } = null!;
    public double Similarity { get; set; }
    public string Content { get; set; } = null!;
}

/// <summary>
/// 向量数据
/// </summary>
public class VectorData
{
    public Guid ChunkId { get; set; }
    public float[] Vector { get; set; } = null!;
    public string Content { get; set; } = null!;
}
